package com.example.liwushuo.adapter;

import java.util.List;

import com.example.liwushuo.BaseApp;
import com.example.liwushuo.R;
import com.example.liwushuo.bean.HomeGridBase;
import com.example.liwushuo.bean.Promotion;

import android.content.Context;
import android.content.res.ColorStateList;
import android.graphics.Color;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

public class GridAdapter extends AppAdapter<Promotion> {

	public GridAdapter(Context context, List<Promotion> list) {
		super(context, list);
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {

		ViewHolder holder;
		if (convertView == null) {

			convertView = inflater.inflate(R.layout.selection_gridview_item,
					null);
			holder = new ViewHolder(convertView);
			convertView.setTag(holder);
		} else {
			holder = (ViewHolder) convertView.getTag();
		}

		Promotion promotion = list.get(position);

		holder.title.setText(promotion.getTitle());
		holder.title.setTextColor(Color.parseColor(promotion.getColor()));

		BaseApp.getBitmapUtils().display(holder.img,
				promotion.getIcon_url());

		return convertView;
	}

	private static class ViewHolder {
		ImageView img;
		TextView title;

		public ViewHolder(View view) {
			img = (ImageView) view.findViewById(R.id.selection_gridview_img);
			title = (TextView) view.findViewById(R.id.selection_gridview_title);
		}
	}
}
